package com.mjf.jst.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mjf.jst.domain.WMSWarehouse;
import com.mjf.jst.mapper.WMSWarehouseMapper;
import com.mjf.jst.service.IWMSWarehouseService;
import com.mjf.jst.service.JSTAsyncService;
import com.mjf.jst.vo.ShopInfoVO;
import com.mjf.jst.vo.WMSInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * desc
 * </p>
 *
 * @author chenshoumeng
 * @date 2025/8/11 13:12
 */
@Service
public class WMSWarehouseServiceImpl extends ServiceImpl<WMSWarehouseMapper, WMSWarehouse> implements IWMSWarehouseService {


    @Autowired
    private JSTAsyncService asyncService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pullWmsList() {
        List<WMSInfoVO.WMSInfoDataList> wmsList = asyncService.pullWmsList();
        if (CollectionUtil.isNotEmpty(wmsList)) {
            return;
        }
        List<WMSWarehouse> wmsWarehouses = new ArrayList<>();

        for (WMSInfoVO.WMSInfoDataList wmsInfoDataList : wmsList) {
            WMSWarehouse wmsWarehouse = new WMSWarehouse();
            wmsWarehouse.setName(wmsInfoDataList.getName());
            wmsWarehouse.setCoId(wmsInfoDataList.getCo_id());
            wmsWarehouse.setWmsCoId(wmsInfoDataList.getWms_co_id());
            wmsWarehouse.setIsMain(wmsInfoDataList.getIs_main());
            wmsWarehouse.setStatus(wmsInfoDataList.getStatus());
            wmsWarehouse.setRemark1(wmsInfoDataList.getRemark1());
            wmsWarehouse.setRemark2(wmsInfoDataList.getRemark2());
            wmsWarehouses.add(wmsWarehouse);
        }
        saveOrUpdateBatch(wmsWarehouses);
    }
}
